/**
 * 
 */
package cc.monggo.third.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Date;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author Administrator
 *
 */
public class HohaibookClient {
	static Log logger = LogFactory.getLog(HohaibookClient.class);
	
	/**
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException {
		HohaibookClient client = new HohaibookClient();
		client.visitHohaibook();
		
		for(int i=0;i<1000;i++){
			client.visitHohaibook();
			Thread.currentThread().sleep(10000);
		}
	}
	
	public void visitHohaibook(){
		String time = new Date().getTime()+"";
		String path = "?_t="+time;
		GetMethod method = new GetMethod(path);
		HttpClient client = new HttpClient();
		client.getHostConfiguration().setHost("www.hohaibook.com",80,"http");
		
		try {
			client.executeMethod(method);
			if(method.getStatusCode() == 200){		
				logger.info("请求成功");
				BufferedReader buffer = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(),"UTF-8"));
				StringBuffer body = new StringBuffer();
				for(String tempstr = ""; (tempstr = buffer.readLine()) != null;){
					body = body.append(tempstr);
				}
				System.out.println(body);
			}else{
				logger.warn("请求失败");
			}
		} catch (HttpException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		finally{
			method.releaseConnection();
		}
	}

}
